<?= $this->Html->script('multi_inputs', array('inline'=>false)) ?>

<?php

    $store = @$data['Store'];
    $users = @$data['User'];debug($store);
    if (empty($users)) {
        $users = array(array(
            'id' => 0,
            'username' => ''
        ));
    }

?><?= $this->Form->create('Store', array('url'=>'/stores/save', 'class'=>'left', 'enctype'=>'multipart/form-data')) ?>
    
    <?= $this->Form->hidden('id', array('value'=>@$store['id'])) ?>
    
    <?= $this->Form->submit('Sačuvaj', array('div'=>false, 'class'=>'right')) ?>
    <? if ((int)$store['id']>0): ?>
    <?= $this->Form->submit('Obriši', array(
        'div'     => false, 
        'type'    => 'button',
        'class'   => 'right delete',
        'onclick' => 'if(confirm(\'Da li želite da obrišete prodavnicu?\')){location.href=\'/stores/delete/'.$store['id'].'\'}'
    )) ?>
    <? endif ?>
    
    <?= $this->Html->link('&laquo; nazad', '/stores', array('escape'=>false)) ?>
    
    <?= $this->Form->label('logo', 'Logo:') ?>
    <div class="left">
        <?= $this->Form->hidden('logo', array('value'=>@$store['logo'])) ?>
        <?= $this->Html->image('stores/' . @$store['logo'] . "?cb=" . time()) ?>
        <?= $this->Form->file('logo_file') ?>
    </div>
    
    <?= $this->Form->label('name', 'Naziv:') ?>
    <?= $this->Form->text('name', array('value'=>@$store['name'])) ?>
    
    <?= $this->Form->label('address', 'Adresa:') ?>
    <?= $this->Form->text('address', array('value'=>@$store['address'], 'class'=>'large')) ?>
    
    <?= $this->Form->label('phone', 'Telefon:') ?>
    <?= $this->Form->text('phone', array('value'=>@$store['phone'], 'class'=>'large')) ?>
    
    <?= $this->Form->label('email', 'Email:') ?>
    <?= $this->Form->text('email', array('value'=>@$store['email'], 'class'=>'large')) ?>
    
    <hr>
    <?= $this->Form->label('users', 'Korisnici:') ?>
    <div class="left multi-inputs">
        <? foreach($users as $k=>$user): ?>
        <div class="item">
            <?= $this->Form->select("UsersStore.{$k}.user_id", $allUsers, array(
                'value' => @$user['id'],
                'empty' => false
            )) ?>
        </div>
        <? endforeach ?>
    </div>

<?= $this->Form->end() ?>